<?php
include dirname(__FILE__) . "/config/functions.php";

$optionsQuery = mysql_query("SELECT * FROM `option`");
while ($row = mysql_fetch_assoc($optionsQuery))
    $options[$row['key']] = $row['value'];

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$error = '';


    if ($_POST['name'] == '') {
        $error .= 'Name Field can\'t be blank.<br>';
    } elseif (strlen($_POST['name']) > 50) {
        $error .= 'Name Field can\'t exceed 50 charachters.<br>';
    }
    if ($_POST['email'] == '') {
        $error .= 'Email Field can\'t be blank.<br>';
    } elseif (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
        $error .= 'Invalid Email address.<br>';
    }
    if ($_POST['subject'] == '') {
        $error .= 'subject Field can\'t be blank.<br>';
    } elseif (strlen($_POST['subject']) > 50) {
        $error .= 'subject Field can\'t exceed 50 charachters.<br>';
    }
    if ($_POST['message'] == '') {
        $error .= 'message Field can\'t be blank.<br>';
    } elseif (strlen($_POST['message']) > 250) {
        $error .= 'message Field can\'t exceed 250 charachters.<br>';
    }
    

    //if all valid then save and send mail.
    if (!$error) {

        sendMail($_POST['email'], $_POST['subject'], $_POST['message']);
        header("Location: index.php");
    }
}
?>
<!doctype html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]>    <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]>    <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!-- Consider adding a manifest.appcache: h5bp.com/d/Offline -->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <title><?= $options['site_name'] ?></title>
        <meta property="og:title" content="<?= $options['site_name'] ?>">
        <meta property="og:site_name" content="<?= $options['site_name'] ?>">
        <meta property="og:type" content="<?= $options['type'] ?>">
        <meta property="og:url" content="<?= $options['url'] ?>">
        <meta property="og:image" content="<?= $options['image'] ?>">
        <meta property="fb:admins" content="<?= $options['admins'] ?>">
        <meta name="description" content="<?= $options['site_description'] ?>">
        <meta name="keywords" content="<?= $options['keywords'] ?>">
        <meta name="author" content="<?= $options['author'] ?>">
        <meta name="Robots" content="<?= $options['Robots'] ?>">
        <meta http-equiv="Content-Type" content="text/html; charset=windows-1250">
        <link href="css/bootstrap.min.css" rel="stylesheet"/>
        <link href="css/style.css" rel="stylesheet"/>
    </head>
    <body>
        <!-- Save for Web Slices (index.psd) -->
        <table width="950" height="1" border="0" align="center" cellpadding="0" cellspacing="0" id="Table_01">
            <tr>
                <td background="images/bg.png">
                    <img src="images/header.png" alt="Viral Marketing Script - Your MEGA Traffic on Over-Drive!" width="950" height="294" lowsrc="Viral Marketing Script - Your MEGA Traffic on Over-Drive!"></td>
            </tr>
            <tr>
                <td background="images/bg.png"><div align="center"><strong><span class="style4">
                                :: <a href="index.php">Home</a> 
                                :: <a href="contact.php">Contact Us</a> 
                                :: <a href="advertise.php">Advertise</a> 
                                :: <a href="member/login.php">Login</a> 
                                ::</span></strong></div>
                </td>
            </tr>
            <tr>
                <td background="images/bg.png">
                    <div align="center">
                        <div class="container"> 
                            <div style="margin: 7px;"> 
                                <?php $_position = 'top'; ?>
                                <?php include dirname(__FILE__) . '/_banner.php'; ?>
                            </div>
                            <div class="row">

                                <?php if (isset($error)): ?>
                                    <div class="alert alert-danger alert-dismissable">
                                        <?= $error; ?>
                                    </div>
                                <?php endif; ?> 

                                <div class="main text-center text-page"> 
                                    <div style="color: black;" class="signupFormDiv">
                                        <form action="" method="post" class="form-horizontal signupForm" role="form">


                                            <div class="form-group">
                                                <label for="name" class="col-sm-2 control-label">Name</label>
                                                <div class="col-sm-6">
                                                    <input required='required'type="text" class="form-control" name="name" size="15" value="<?= (isset($_POST['name'])) ? $_POST['name'] : ''; ?>">
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label for="email" class="col-sm-2 control-label">Email</label>
                                                <div class="col-sm-6">
                                                    <input required='required'type="text" class="form-control" name="email" size="15"  value="<?= (isset($_POST['email'])) ? $_POST['email'] : ''; ?>">
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label for="subject" class="col-sm-2 control-label">Subject</label>
                                                <div class="col-sm-6">
                                                    <input required='required'type="text" class="form-control" name="subject" size="15"  value="<?= (isset($_POST['subject'])) ? $_POST['subject'] : ''; ?>">
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label for="message" class="col-sm-2 control-label">Message</label>
                                                <div class="col-sm-6">
                                                    <textarea required='required' class="form-control" name="message" size="25" maxlength="100" ><?= (isset($_POST['message'])) ? $_POST['message'] : ''; ?></textarea>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <div class="col-sm-offset-2 col-sm-6">
                                                    <button type="submit" class="btn btn-default">Submit</button>
                                                </div>
                                            </div>
                                        </form>
                                        <div>
                                        </div> 

                                        <div style="margin: 25px;"> 
                                            <?php $_position = 'bottom'; ?>
                                            <?php include dirname(__FILE__) . '/_banner.php'; ?>
                                        </div>

                                    </div> 
                                </div>

                            </div>
                            </td>
                            </tr>
                            <tr>
                                <td background="images/bg.png"><div align="center">
                                        <?php include 'footer.php'; ?>
                                    </div></td>
                            </tr>
                            <tr>
                                <td>
                                    <img src="images/footer.png" width="950" height="108" alt=""></td>
                            </tr>
                            </table>
                            <script src="js/jquery-1.10.2.min.js"></script>
                            <script src="js/bootstrap.min.js"></script>

                            <!-- End Save for Web Slices -->
                            </body>
                            </html>    